<template>
  <div class="withdrawal" ref="withdrawal">
    <group>
      <cell>
        <span slot="title" class="withdrawal_to">提现到微信</span>
      </cell>
    </group>
    <group>
      <x-input class="input_number" type="number" v-model="drawCash" @on-change="inputChange" :placeholder="`单笔交易最低${limitInfo.withdrawal_min_money}元，最高${limitInfo.withdrawal_max_money}元`" required>
        <span slot="label" class="rmb">￥</span>
      </x-input>
      <cell>
        <span class="banlance" slot="title">当前账户余额：{{limitInfo.moneynum}}元</span>
        <span v-if="limitInfo.withdrawal_money_max_limit != 1" class="banlance" slot="inline-desc">可提现余额为：{{(limitInfo.moneynum * limitInfo.withdrawal_money_max_limit).toFixed(2)}}元</span>
        <button slot="default" class="all_draw" @click="allDrawClick">全部提现</button>
      </cell>
    </group>
    <p class="tips">每日最多提现{{limitInfo.withdrawal_max_times}}次，提现时间：{{limitInfo.withdrawal_dat_begin}}-{{limitInfo.withdrawal_dat_end}}，提现间隔时间：{{limitInfo.withdrawal_separate_time_limit/60}}分钟。2小时到账。
      <span v-if="limitInfo.withdrawal_commission_rate_enabled" class="tips_warn">提现每笔收取{{limitInfo.withdrawal_commission_rate*100}}%的手续费。</span>
    </p>
    <agent-button class="draw_btn" @btnClick="drawClick" :disabled="btnEnable">提现</agent-button>
  </div>
</template>

<script>
import AgentButton from "../../../components/common/AgentButton.vue";
import { getUrlString } from "../../../scripts/utils.js";
import { Group, Cell, XInput } from "vux";
export default {
  data() {
    return {
      limitInfo: {},
      drawCash: "",
      taxRate: true
    };
  },
  components: {
    AgentButton,
    Group,
    Cell,
    XInput
  },
  computed: {
    btnEnable() {
      if (this.drawCash) {
        return false;
      }
      return true;
    }
  },
  created() {
    this.limitInfo = JSON.parse(this.$route.query.limitInfo);
  },
  methods: {
    inputChange(value) {
      let that = this;
      if (value == 0 && value != "") {
        this.$vux.alert.show({
          content: "提现金额不为0",
          onShow() {},
          onHide() {
            that.drawCash = "";
          }
        });
        return;
      }
      if (value > this.limitInfo.moneynum) {
        this.$vux.alert.show({
          content: "提现金额不能超过账户余额",
          onShow() {},
          onHide() {
            that.drawCash = "";
          }
        });
        return;
      }
    },
    drawClick() {
      let beginTime = Number(this.limitInfo.withdrawal_dat_begin.split(":")[0]);
      let endTime = Number(this.limitInfo.withdrawal_dat_end.split(":")[0]);
      let nowTime = new Date().getHours();
      let _this = this;
      if (this.drawCash % this.limitInfo.withdrawal_mod_base !== 0) {
        this.$vux.alert.show({
          content: `提现金额必须是${
            this.limitInfo.withdrawal_mod_base
          }的整数倍`,
          onShow() {},
          onHide() {
            _this.drawCash = "";
          }
        });
        return;
      }
      if (beginTime > nowTime || endTime < nowTime) {
        this.$vux.alert.show({
          content: `当前不在提现的时间范围内`
        });
        return;
      }
      console.log(location.protocol);
      this.apiService.Payment4.order({
        money: this.drawCash,
        backurl: location.protocol + "//" + location.hostname + "/wechat"
      }).then(res => {
        let _this = this;
        location.href = res.data.url;
      });
    },
    allDrawClick() {
      if (
        this.limitInfo.moneynum * this.limitInfo.withdrawal_money_max_limit ==
        0
      ) {
        this.$vux.alert.show({
          content: `当前暂无可提现金额`
        });
        return;
      }
      this.drawCash = this.limitInfo.moneynum;
    }
  }
};
</script>

<style>
input::-webkit-input-placeholder {
  font-size: initial;
}
</style>


<style scoped>
.withdrawal_to {
  color: #000;
  font-size: 0.32rem;
}
.withdrawal_title {
  font-size: 0.32rem;
}
.rmb {
  color: #333;
  font-size: 0.5rem;
}
.input_number {
  font-size: 0.7rem;
}
.banlance {
  color: var(--word-gray-color);
  font-size: var(--word-common-size);
}
.all_draw {
  color: #3aa6f8;
  font-size: var(--word-common-size);
}
.tips {
  color: var(--word-gray-color);
  padding: 0.3rem;
}
.tips_warn {
  color: var(--word-warn-color);
}
.draw_btn {
  width: 90%;
}
</style>


